<!--<!DOCTYPE html>-->
<!--<html lang="en">-->
<!--<head>-->
<!--    <meta charset="UTF-8">-->
<!--    <title>{{ user.name }}'s Watchlist</title>-->
<!--    <link rel="stylesheet" class="avatar" href="{{ url_for('static',filename='css/style.css') }}" type="text/css">-->
<!--</head>-->
<!--<body>-->
<!--    <h2>-->
<!--        <img alt="Avatar" src="{{ url_for('static',filename='images/totoro.gif') }}">-->
<!--        {{ user.name }}'s Watchlist-->
<!--    </h2>-->
<!--    <p>{{ movies|length }} Titles</p>-->
<!--    <ul>-->
<!--        {% for movie in movies %}-->
<!--        <li>{{ movie.title }} - {{ movie.year }} </li>-->
<!--        {% endfor %}-->
<!--    </ul>-->
<!--    <img alt="Walking Totoro" class="totoro" src="{{ url_for('static',filename='images/totoro.gif') }}">-->
<!--    <footer>-->
<!--        <small>&copy;2018 <a href="http://helloflask.com/totorial">HelloFlask</a> </small>-->

<!--    </footer>-->


<!--</body>-->
<!--</html>-->

{% extends 'base.html' %}
{% block content %}

<p>{{ movies|length }}Titles</p>
<!--在模板中可以直接使用current_user变量-->
{% if current_user.is_authenticated %}
<form method="post">

    Name <input type="text" name="title" autocomplete="off" required>

    Year <input type="text" name="year" autocomplete="off" required>
    <input class="btn" type="submit" name="submit" value="Add">
</form>
{% endif %}
<ul class="movie-list">
    {% for movie in movies %}
    <li>{{ movie.title }} - {{ movie.year }}
        <span class="float-right">
            {% if current_user.is_authenticated %}
            <a class="btn" href="{{ url_for('edit',movie_id=movie.id) }}">Edit</a>
            <form class="inline-form" method="post" action="{{ url_for('delete', movie_id=movie.id) }}">
                <input class="btn" type="submit" name="delete" value="Delete" onclick="return confirm('Are you sure?')">
            </form>
            {% endif %}
        <a class="imdb" href="https://www.imdb.com/find?q={{ movie.title }}" target="_blank" title="Find this on IMDb">IMDb</a>

    </span>
    </li>
    {% endfor %}

</ul>
<img alt="Walking Totoro" class="totoro" src="{{ url_for('static',filename='images/totoro.ico') }}" title="to~to~ro">
{% endblock %}